package com.akoj.anmu.exception;

import com.akoj.anmu.common.BaseResponse;
import com.akoj.anmu.common.ResponseCode;
import com.akoj.anmu.common.ResultUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理类
 */
@RestControllerAdvice
public class GlobalException {

    //自定义异常处理
    @ExceptionHandler(value = BusinessException.class)
    public BaseResponse businessExceptionHandler(BusinessException e){
        return ResultUtils.error(e.getCode(),e.getMessage());
    }

    @ExceptionHandler(value = RuntimeException.class)
    public BaseResponse runtimeExceptionHandler(RuntimeException e){
        return ResultUtils.error(ResponseCode.SERVER_ERROR.getCode(),ResponseCode.SERVER_ERROR.getMessage());
    }

}
